package com.starrin.tennisfinder.extractors;

import com.starrin.tennisfinder.model.VenueAvailabilityDataHolder;
import com.starrin.tennisfinder.util.ExtractorUtil;

import java.util.HashSet;
import java.util.Set;

/**
 * User: Starrin
 * Date: 2013-10-31
 * Time: 21:45
 */
public class AvailabilityExtractorCommodus {

    public static final String COMMODUS_PATTERN_TEMPLATE = "STATE=3&ITEM=(%s{1})&YEAR=[0-9]{4}&MONTH=[0-9]{1,2}&DAY=[0-9]{1,2}&HOUR=(?<hour>[0-9]{1,2})";

    public VenueAvailabilityDataHolder extractVenueAvailability(String response, String url, String indoorItems, String outdoorItems) {

        Set<Integer> availableHoursIndoors = new HashSet<>();
        if(indoorItems != null) {
            String patternStringIndoors =  String.format(COMMODUS_PATTERN_TEMPLATE, indoorItems);
            availableHoursIndoors = ExtractorUtil.getAvailableHours(patternStringIndoors, response);
        }

        Set<Integer> availableHoursOutdoors = new HashSet<>();
        if(outdoorItems != null) {
            String patternStringOutdoors =  String.format(COMMODUS_PATTERN_TEMPLATE, outdoorItems);
            availableHoursOutdoors = ExtractorUtil.getAvailableHours(patternStringOutdoors, response);
        }
        return ExtractorUtil.getVenueAvailabilityDataHolder(url, availableHoursIndoors, availableHoursOutdoors);
    }




}
